package text;

import java.util.Arrays;
import java.util.Random;

public class ACM {

    public static void main(String[] args) {
    shout();
    }
    public static void shout(){
        Random random = new Random();
        String[] na = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x",
                "y","z"};
        String[][] array = new String[10][3];
        System.out.println("数组原样");
        for (int i = 0; i < array.length; i++) {
            /*
             * @param name 队伍名字
             * @param number 答题数量
             * @param time 答题时间*/
            int number = random.nextInt(21);
            int time = random.nextInt(91);
            int name = random.nextInt(na.length);
            array[i][0] = na[name];
            array[i][1] = String.valueOf(number);
            array[i][2] = String.valueOf(time);
            System.out.println(Arrays.toString(array[i]));
        }
        System.out.println("排序后的数组");
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                if (Integer.valueOf(array[j][1]) < Integer.valueOf(array[j+1][1])){
                    String[] temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                }else if (Integer.valueOf(array[j][1]) == Integer.valueOf(array[j+1][1])){
                    if (Integer.valueOf(array[j][2]) > Integer.valueOf(array[j+1][2])){
                        String[] temp = array[j+1];
                        array[j+1] = array[j];
                        array[j] = temp;
                    }
                }
            }
        }
        for (int i = 0; i < array.length; i++) {
            System.out.println(Arrays.toString(array[i]));
        }
    }
}
